package com.ktwlsoft.archivemanage.controller.guiBusiness;


import com.ktwlsoft.archivemanage.domain.business.businessService.guiBusiness.BusinessGuidanceService;
import com.ktwlsoft.archivemanage.payload.businessGuidance.BusinessGuidanceSaveRequest;
import com.ktwlsoft.archivemanage.payload.businessGuidance.BusinessGuidanceUpdateRequest;
import com.ktwlsoft.archivemanage.payload.businessGuidance.UnitConfirmRequest;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.payload.guiBusiness.CommitRequest;
import com.ktwlsoft.archivemanage.payload.guiBusiness.GuiBusinessPageRequest;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 业务指导控制器
 *
 * @author zhuhe on 2020-03-12 14:07:50
 * @version 1.0
 */
@Api(value = "业务指导控制器", description = "业务指导控制器")
@RestController
@RequestMapping("guiBusinessGuidance")
public class GuiBusinessGuidanceController{
	private final BusinessGuidanceService businessGuidanceService;
	public GuiBusinessGuidanceController(BusinessGuidanceService businessGuidanceService) {
		this.businessGuidanceService = businessGuidanceService;
	}

    /**
     * 业务指导新增 on 2019/11/6 16:55
     *@author liyi on 2019/3/13 9:15
     * @param request request
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "业务指导新增", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("save")
    @UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_ADD")
    public ResponseEntity<?> save(@Valid @RequestBody BusinessGuidanceSaveRequest request) {
        return ResponseEntity.ok(businessGuidanceService.save(request));
    }

	/**
	 *业务指导更新 2020-3-17 9:37
	 * @author liyi 2020-3-17 9:37
	 * @param request request
	 * @return ResponseEntity<?>
	 * */
	@ApiOperation(value = "业务指导更新", httpMethod = "POST", produces="application/json", response = ResponseEntity.class)
    @ResponseBody
	@PostMapping("update")
	@UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_EDIT")
	public ResponseEntity<?> update (@Valid @RequestBody BusinessGuidanceUpdateRequest request) {
		return ResponseEntity.ok(businessGuidanceService.update(request));
	}

	/**
	 * 提交 on 2020/3/12 14:44
	 *
	 * @param commitRequest commitRequest
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "提交")
	@ResponseBody
	@PostMapping("commit")
	public ResponseEntity<?> commit(@RequestBody CommitRequest commitRequest) {
		return ResponseEntity.ok(businessGuidanceService.commit(commitRequest));
	}

	/**
	  * 查看业务指导 on 2020/3/12 14:44
	  *
	  * @param id id
	  * @return ResponseEntity<?>
	  */
	@ApiOperation(value = "查看业务指导")
	@ResponseBody
	@GetMapping("getDetails")
	@UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_DETAILS", skip = true)
	public ResponseEntity<?> getDetails(@ApiParam(name = "id", value = "业务指导主键") @RequestParam Long id) {
		return ResponseEntity.ok(businessGuidanceService.getDetails(id));
	}

	/**
	 * 删除业务指导 on 2020/3/12 14:44
	 *
	 * @param id id
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "删除业务指导")
	@ResponseBody
	@GetMapping("delete")
	@UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_DELETE")
	public ResponseEntity<?> delete(@ApiParam(name = "id", value = "业务指导主键") @RequestParam Long id) {
		return ResponseEntity.ok(businessGuidanceService.delete(id));
	}

	/**
	 * 业务指导分页
	 *
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "业务指导分页")
	@GetMapping("/findPage")
	@UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_PAGE", skip = true)
	public ResponseEntity<?> findPage(@Valid GuiBusinessPageRequest request) {
		Result result = businessGuidanceService.findPage(request);
		return ResponseEntity.ok(result);
	}

	@ApiOperation(value = "获取指导员下拉列表", httpMethod = "GET")
	@GetMapping("/getInstructorList")
	public ResponseEntity<?> getInstructorList() {
		return ResponseEntity.ok(Result.ok(businessGuidanceService.getInstructorList()));
	}

	/**
	 * 业务指导分页用户端
	 *
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "业务指导分页用户端")
	@GetMapping("/wxFindPage")
	public ResponseEntity<?> wxFindPage(@Valid GuiBusinessPageRequest request) {
		Result result = businessGuidanceService.userFindPage(request);
		return ResponseEntity.ok(result);
	}

	/**
	 * 查看业务指导用户端
	 *
	 * @param id id
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "查看业务指导用户端")
	@ResponseBody
	@GetMapping("/wxGetDetails")
	public ResponseEntity<?> wxGetDetails(@ApiParam(name = "id", value = "业务指导主键") @RequestParam Long id) {
		return ResponseEntity.ok(businessGuidanceService.getDetails(id));
	}

	/**
	 * 归档:归档或取消归档
	 *
	 * @param id id
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "归档:归档或取消归档")
	@ResponseBody
	@GetMapping("archive")
	public ResponseEntity<?> archive(@ApiParam(name = "id", value = "业务指导主键") @RequestParam Long id) {
		return businessGuidanceService.archive(id);
	}

    /**
     * 撤销
     *
     * @param id id
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "撤销")
    @ResponseBody
    @GetMapping("revoke")
    public ResponseEntity<?> revoke(@ApiParam(name = "id", value = "业务指导主键") @RequestParam Long id) {
        return businessGuidanceService.revoke(id);
    }

	/**
	 * 获取当前指导人已上报条数
	 *
	 * @param userId userId
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "获取当前指导人已上报条数")
	@ResponseBody
	@GetMapping("getRecorderMount")
	public ResponseEntity<?> getRecorderMount(@ApiParam(name = "userId", value = "指导员id") @RequestParam Long userId) {
		Result result = businessGuidanceService.getRecorderMount(userId);
		return ResponseEntity.ok(result);
	}

	/**
	 * 立档单位确认
	 *
	 * @param request UnitConfirmRequest
	 * @return ResponseEntity<?>
	 */
	@ApiOperation(value = "立档单位确认")
	@ResponseBody
	@PostMapping("unitConfirm")
	public ResponseEntity<?> unitConfirm(@Valid  @RequestBody UnitConfirmRequest request,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResponseEntity.ok(Result.body(request, ResultType.CHECK_ERROR).withMessage(bindingResult.getFieldError().getDefaultMessage()));
		}
		return ResponseEntity.ok(businessGuidanceService.unitConfirm(request));
	}
}